import axios from "axios";
export default {
    namespaced: true,
    state:{
        messageList:[],
        userApplyList:[]
    },
    getters:{},
    mutations:{
        //门店申请
        getApplyList(state,data){
            // console.log(data)
            if(data === false){
                console.log("当前没有门店申请")
            }else{
                let newData = data.map(item => {
                    if(item.type == "1"){
                        return { ...item,type: '门店管理员申请'}
                    }else if(item.type == "2"){
                        return { ...item, type: '新门店申请'}
                    }else if(item.type == "3"){
                        return { ...item, type: '注销门店申请'}
                    }else {
                        console.log('type 有误!')
                    }
                })
                state.messageList = newData.map(item =>{
                    if(item.status == "1"){
                        return { ...item, status: '申请中'}
                    }else if(item.status == "2"){
                        return { ...item, status: '已通过'}
                    }else if(item.status == "3"){
                        return { ...item, status: '未通过'}
                    }else {
                        console.log('status 错误!')
                    }
                })
            }
        },
        // 管理员申请
        getApplyUserList(state,data){
            // state.userApplyList = data
            if(data===false){
                console.log("当前没有管理员申请")
            }else{
                let newData = data.map(item => {
                    if(item.userType == "1"){
                        return { ...item,userType: '门店管理员'}
                    }else if(item.userType == "2"){
                        return { ...item, userType: '平台管理员'}
                    }else {
                        console.log('userType 有误!')
                    }
                })
                state.userApplyList = newData.map(item =>{
                    if(item.userStatus == "0"){
                        return { ...item, userStatus: '申请中'}
                    }else if(item.userStatus == "1"){
                        return { ...item, userStatus: '可用'}
                    }else if(item.userStatus == "2"){
                        return { ...item, userStatus: '不可用'}
                    }else {
                        console.log('userStatus 错误!')
                    }
                })
            }
        }
    },
    actions: {
        // 获取门店申请
        getShopsList(context){
            axios
            .get('/shops')
            .then(res => {
                context.commit('getApplyList',res.data)
            })
        },
        //获取管理员申请
        getAdminList(context){
            axios
            .post('/admins/getApplyUser')
            .then(res => {
                console.log(res.data)
                context.commit('getApplyUserList',res.data)
            })
        }
    }
}